home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Using char array in functions
- Date: 01 Mar 1996 16:27:39 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar1092739@qcd.lanl.gov>
- References: <20FEB199609155775@sundog.caltech.edu> <4gqk5m$jno@aphex.direct.ca>
- <1996Feb29.230019.5028@isac.hces.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: gg@isac.hces.com's message of Thu, 29 Feb 1996 23:00:19 GMT
-
- In article <1996Feb29.230019.5028@isac.hces.com>
- gg@isac.hces.com (Greg Goodrich) writes:
-
- <snip>
- GG: /* declaration */
- GG: char array1[100];
- GG:
- GG: main()
- GG: {
- GG: foo(array1);
- GG: }
- GG:
- GG: In this example, the function foo() can modify any member of the array
- GG: "array1" at will. You do not have to pass the address of the array
- GG: name, because by using the array name, you are actually passing
- GG: &array1[0], or in english, the address of the first member of the array,
- GG: which for argument's sake is also the address of the array. This allows
-
- It may be the address of the array, but because of past confusion, one
- must point out that it is a char *, not char (*)[100]. The proper
- `address of the array' is of the latter type.
-
- I usually assume, if I have to, that (void*)array == (void*)&array,
- though, strictly speaking, the standard does not guarantee that. That
- does not mean the two are interchangeable: (double)2 == (double)2.0,
- but as anyone who has used C knows, passing one instead of the other
- can be a disaster!
-
- GG: any manipulation of the array inside the function that the function
-
- The reason the manipulation is possible is because given the two
- facts:
- 1) The array elements are contiguous
- 2) The function has a pointer to the first element
- it can actually construct the pointer to any element in the array it
- needs. Because of this, it can modify any element: and when every
- element of an array can be modified, we think of it as `the array can
- be modified'.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-